package com.ypf.demo_ssm.config;

import com.ypf.demo_ssm.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 使用拦截器，拦截路径下的所有请求进行token身份验证，但是放行swagger login register 相关等
 */
@Configuration  //把配置类添加到ioc容器中
public class InterceptConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器
        registry.addInterceptor(new JWTInterceptor())
                //拦截的路径 需要进行token验证的路径
                .addPathPatterns("/**")
                //放行的路径
                .excludePathPatterns("/api/login", "/api/register", "/swagger-ui.html/**", "/v3/api-docs/**", "/doc.html/**", "/webjars/**");
    }

}
